#include<iostream>
#include<string.h>
#include<memory.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

bool IsAnagram1(string s,string t)
{
	if(s.length()!=t.length()) return false;
	int len = s.length();
	int flag[256]={0} , i;
	memset(flag,0,sizeof(flag));
	int num_unique_chars=0;
	int num_completed_t=0;
	for(i=0;i<len;i++)
	{
		int loc=(int)s[i];
		if(flag[loc]==0) ++num_unique_chars;
		++flag[loc];
	}
	for(i=0;i<len;i++)
	{
		int loc=(int)t[i];
		if(flag[loc]==0)  return false;
		--flag[loc];
		if(flag[loc]==0)
		{
			++num_completed_t;
			if(num_unique_chars == num_completed_t)
			{
				return (i == len-1)?true:false;
			}
		}
	}
	return false;
}

bool IsAnagram2(string s,string t)
{
	if( s.length()!=t.length() ) return false;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	return ( s==t ) ? true:false;
}

int main()
{
	string s="abcde";
	string t="edcba";
	string s1="abcabcabc";
	string t1="cbacbacba";
	string s2="aaabbb";
	string t2="bbbccc";

	if(IsAnagram1(s,t))  cout<<"IsAnagram"<<endl;
	else cout<<"IsNotAnagram"<<endl;

	if(IsAnagram1(s1,t1))  cout<<"IsAnagram"<<endl;
	else cout<<"IsNotAnagram"<<endl;

	if(IsAnagram1(s2,t2))  cout<<"IsAnagram"<<endl;
	else cout<<"IsNotAnagram"<<endl;

	return 0;
}
